/*
 */

package ihmprojet;

import edu.uci.ics.jung.algorithms.layout.KKLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import java.awt.Dimension;
import javax.swing.JFrame;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class SimpleGraphView {
    Graph<Integer, String> g;
    /** Creates a new instance of SimpleGraphView */
    public SimpleGraphView() {
        // Graph<V, E> where V is the type of the vertices and E is the type of the edges
        g = new SparseMultigraph<Integer, String>();
        // Add some vertices. From above we defined these to be type Integer.
                Integer v1 = 1;
                Integer v2 = 2;
                Integer v3 = 3;
                Integer v4 = 4;
                Integer v5 = 5;
                g.addVertex(v1);
                g.addVertex(v2);
                g.addVertex(v3);
                g.addVertex(v4);
                g.addVertex(v5);
                g.addEdge("1->", v1, v2);
                g.addEdge("2->", v1, v3);
                g.addEdge("3->", v1, v4);
                g.addEdge("4->", v1, v5);
    }
    

    public static void main(String[] args) {
        SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here
        // The Layout<V, E> is parameterized by the vertex and edge types
        Layout<Integer, String> layout = new KKLayout(sgv.g);
        layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
        // The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
        BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
        vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size
        
        JFrame frame = new JFrame("Simple Graph View");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(vv); 
        frame.pack();
        frame.setVisible(true);       
    }
    
}
